package com.phone.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.phone.entity.Admin;
import com.phone.entity.Store;
import com.phone.entity.User;
import com.phone.service.AdminService;
import com.phone.service.UserService;

@Controller
public class AdminController {
	@Resource
	private AdminService adminServiceimpl;
	@Resource
	private UserService userServiceImpl;
	@RequestMapping("alluser")
	public String alluser(Model model,HttpServletRequest request){
		String username = request.getParameter("username");
		Admin admin=userServiceImpl.selea(username);
		model.addAttribute("admin", admin);
		List<User> all=adminServiceimpl.alluser();
		model.addAttribute("all", all);
		return "/all.jsp";
	}
	@RequestMapping("allstore")
	public String allstore(Model model,HttpServletRequest request){
		String username = request.getParameter("username");
		Admin admin=userServiceImpl.selea(username);
		model.addAttribute("admin", admin);
		List<Store> all=adminServiceimpl.allstore();
		model.addAttribute("all", all);
		return "/all.jsp";
	}
	@RequestMapping(value="upadmin",method=RequestMethod.POST)
	public String upadmin(HttpSession session,Admin admin){
		adminServiceimpl.upadmin(admin);
		session.setAttribute("message", "修改成功!");
		return "allproduct";
	}
}
